package com.dify.tool.common.model;

import com.dify.tool.common.constant.BaseStatus;
import com.dify.tool.common.constant.CommonStatus;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author shl
 * @date 2024-06-24
 */
@Data
@NoArgsConstructor
public class DefaultResponse<T> implements Serializable {
    /**
     * 业务状态码
     */
    private String code;
    /**
     * 业务状态描述
     */
    private String message;
    /**
     * 返回数据
     */
    private T data;

    public static <T> DefaultResponse fail() {
        return fail(CommonStatus.FAILURE);
    }

    public static <T> DefaultResponse fail(BaseStatus baseStatus) {
        return fail(baseStatus.getCode(), baseStatus.getMessage());
    }

    public static <T> DefaultResponse fail(String code, String message) {
        return new DefaultResponse(code, message);
    }

    public static <T> DefaultResponse success() {
        return success(CommonStatus.SUCCESS);
    }

    public static <T> DefaultResponse success(T data) {
        return success(CommonStatus.SUCCESS, data);
    }

    public static <T> DefaultResponse success(BaseStatus baseStatus, T data) {
        return success(baseStatus.getCode(), baseStatus.getMessage(), data);
    }

    public static <T> DefaultResponse success(BaseStatus baseStatus) {
        return success(baseStatus.getCode(), baseStatus.getMessage());
    }

    public static <T> DefaultResponse success(String code, String message) {
        return success(code, message, null);
    }

    public static <T> DefaultResponse success(String code, String message, T data) {
        return new DefaultResponse(code, message, data);
    }

    public DefaultResponse(String code, String message) {
        this(code, message, null);
    }

    public DefaultResponse(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

}
